#include <cmath>
#include <iostream>

// #include "impl/sum_three.h"
#include "base.h"

struct Bar
{
    string title;
    int depth;
    Bar(int dep) : depth(dep) {}
};
int main()
{
    string str = "# one1\n"
                 "balabla\n"

                 "#### four1\n"
                 "enenen\n"

                 "## two1\n"
                 "balabal\n"

                 "#### four2\n"
                 "xixihaha\n"

                 "##### five1\n"
                 "hehehehe\n"

                 "#### four3\n"
                 "jijizhazha\n";
    vector<Bar> final;
    int state = 0;
    int begin_pos = 0;
    int sharp_cnt = 0;
    int level_map[6] = {0};

    for (int i = 0; i < str.size(); i++)
    {
        auto zm = str[i];
        if (state == 0)
        {
            if (str[i] == '#')
            {
                sharp_cnt++;
                // final.push_back(Bar());
                // state = 1;
            }
            else if (str[i] == ' ')
            {
                if (sharp_cnt < 5)
                {
                    final.push_back(Bar(sharp_cnt - 1));
                    state = 2;
                    begin_pos = i;
                    level_map[sharp_cnt - 1] = 1;
                }
                sharp_cnt = 0;
            }
        }
        else if (state == 2)
        {
            if (str[i] == '\n')
            {
                state = 0;
                final[final.size() - 1].title = str.substr(begin_pos + 1, i - begin_pos - 1);
            }
        }
    }

    for (int i = 0; i < final.size(); i++)
    {
        if (level_map[i])
        {
            for (int j = 0; j < i; j++)
            {
                if (level_map[j])
                {
                    level_map[i]++;
                }
            }
        }
        // level_map[final[i].depth] = 1;
    }
    for (auto &a : final)
    {
        a.depth = level_map[a.depth - 1];
    }
    return 0;
}